﻿
#include "cxiimagelabeltest.h"
#include "../../../controls/include/controls/imagelabel/cxiimagelabel.h"

#include <QApplication>
CxiImageLabelTest::CxiImageLabelTest(QObject* parent)
	: QObject(parent)
{

}
CxiImageLabelTest::CxiImageLabelTest(int argc, char** argv, QObject* parent)
{
	m_app = new QApplication(argc, argv);
	m_widget = new QWidget;
	m_imageLabel = new CxiImageLabel(m_widget);
	label = new QLabel("测试图片",m_widget);
	label->move(100, 100);

	label->resize(150, 200);
	label->setScaledContents(true);
	label->setStyleSheet("border: 2px solid black; background-color: lightgray;");

	m_widget->resize(800, 600);

	m_imageLabel->move(300, 300);
	m_imageLabel->resize(300, 300);
	// qDebug() << size;
	m_imageLabel->setScaledContents(true);
	m_imageLabel->setKeepAspectRatio(true);
	m_imageLabel->setStyleSheet("border: 2px solid black; background-color: lightgray;");
	m_widget->show();
}
CxiImageLabelTest::~CxiImageLabelTest()
{
	delete m_app;
	delete m_widget;
}
void CxiImageLabelTest::initTestCase()
{

}
void CxiImageLabelTest::tstImageLoad()
{
	//此处可以先运行tst_codegenerator生成图片，再运行本测试用例
	bool ok = m_imageLabel->loadFromFile("testCode/custom/CODE_128.png");
	if (!ok)
	{
		return;
	}
	auto size = m_imageLabel->pixmap()->size();

	QPixmap* pixmap = new QPixmap;
	pixmap->load("testCode/custom/CODE_128.png");
	label->setPixmap(*pixmap);
	delete pixmap;

	QTimer::singleShot(2000, [this]() {
		m_imageLabel->resize(200,300);
		label->resize(200,300);
	});
	QTimer::singleShot(3000, [this]() {
		m_imageLabel->setScaledContents(true);
		m_imageLabel->setKeepAspectRatio(false);
	});
	QTimer::singleShot(4000, [this]() {
		m_imageLabel->setKeepAspectRatio(true);
	});

	pixmap=nullptr;
}
void CxiImageLabelTest::cleanupTestCase()
{
	m_app->exec();
}

int main(int argc, char** argv)
{
	CxiImageLabelTest tc(argc, argv);
	return QTest::qExec(&tc, argc, argv);
}